//
//  Macro_Device.swift
//  YiZhangGui
//
//  Created by Mac on 2018/1/19.
//  Copyright © 2018年 Mac. All rights reserved.
//

import UIKit
import AppTrackingTransparency
import AdSupport
//import CNUIBaseKit

/// 🍵 打印信息
///
/// eg: cn_Log(message: "")
///

public func cn_Log<T>(message: T, fileName: String = #file, methodName: String = #function, lineNumber: Int = #line) {
    #if DEBUG
        print("\n🍵🍵🍵\n当前文件：\((fileName as NSString).lastPathComponent)[\(lineNumber)行]打印方法：\(methodName)\n输出信息：\(message)\n🍵🍵🍵")
    #endif
}

// TODO: 适配尺寸
///
///  cn_scale(17)
///
public func cn_scale(_ ofSize: CGFloat) -> CGFloat {
    
    var size: CGFloat = 0.0
    if UIDevice.current.userInterfaceIdiom == UIUserInterfaceIdiom.phone {
        size = ofSize * UIScreen.main.bounds.size.width / 375.0
    } else {
        size = ofSize * UIScreen.main.bounds.size.width / 1024.0
    }
    return size
}

/// 屏幕宽和高
public let cn_Width_Screen  = UIScreen.main.bounds.width
public let cn_Height_Screen = UIScreen.main.bounds.height

/// 状态栏高度
public var cn_statusBarHeight: CGFloat {
    if #available(iOS 13.0, *) {
        guard let statusBarManager = UIApplication.shared.windows.first?.windowScene?.statusBarManager else {
            return 0.00
        }
        return (statusBarManager.statusBarFrame.size.height)
    } else {
        return UIApplication.shared.statusBarFrame.size.height
    }
}

/// 本地版本号
public let cn_APP_version = (Bundle.main.infoDictionary!["CFBundleShortVersionString"] as! String)

/// adid
/// 请求AppTrackingTransparency许可
public func requestAdPermission() -> String {
    if #available(iOS 14.0, *) {
        var str = ""
        ATTrackingManager.requestTrackingAuthorization { (status) in
            if status == .authorized {
                str = ASIdentifierManager.shared().advertisingIdentifier.uuidString
            }
            if status == .denied {
                str = "用户不允许获取adid"
            }
        }
        return str
    } else {
        return ASIdentifierManager.shared().advertisingIdentifier.uuidString
    }
}


/***
 * "常见问题"
 * "联系我们"
 * "返利规则"
 */                   
//public let baseURL = "http://YiZhangGui.51dh.vip/"
public let baseURL = "http://danone.91dh.com.cn/"

// TODO: 监听网络
public func cn_listeningNet() {
    /// 监听网络
//    Macro_Network.shared.listening()
//    Macro_Network.shared.changeNetworkBlock = { (networkType) -> Void in
//        switch networkType {
//        case .wifi:
//            UIApplication.shared.keyWindow?.showTips(title: "正在使用Wifi网络")
//        case .cellular:
//            UIApplication.shared.keyWindow?.showTips(title: "正在使用蜂窝网络")
//        case .unavailable, .none:
//            let alert = UIAlertController(title: "温馨提示", message: "网络已断开，请检查网络连接", preferredStyle: .alert)
//            let ok = UIAlertAction(title: "我知道了", style: .cancel, handler: nil)
//            alert.addAction(ok)
//            UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
//        case .appNetworkDidClose:
//            let alert = UIAlertController(title: "温馨提示", message: "App的网络权限未开启", preferredStyle: .alert)
//            let ok = UIAlertAction(title: "我知道了", style: .cancel, handler: nil)
//            alert.addAction(ok)
//            UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
//        }
//   }
}
